package cn.wgx.modules.sys.entity.mapper;

import org.apache.ibatis.annotations.Select;

import java.util.Map;

public interface SysUserFavoriteExtendMapper {


    //按人统计收藏数量
    @Select("select count(case when type=1 then 1 end) course," +
            "count(case when type=2 then 1 end) homework," +
            "count(case when type=3 then 1 end) note ," +
            "count(case when type=4 then 1 end) follow " +
            "from sys_user_favorite where user_id = #{user_id} and (type = 1 or type = 2 or type = 3 or type = 4)")
    Map getFavAllCountByUserId(Integer user_id);

    @Select("select count(*) count " +
            "from sys_user_favorite where user_id = #{user_id} and type = #{type}")
    Integer getFavCountByUserId(Integer user_id, Integer type);


    //按资源统计被收藏数量
    @Select("select count(*) count " +
            "from sys_user_favorite where res_id = #{res_id} and type = #{type}")
    Integer getFavCountResId(Integer res_id, Integer type);


    //按资源统计被收藏数量
    @Select("select count(*) count " +
            "from sys_user_like where res_id = #{res_id} and type = #{type}")
    Integer getLikeCountResIdAndType(Integer res_id, Integer type);

}
